package com.jiang.factory;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.sql.Connection;

public class DAOFactory {

	private DAOFactory(){
		
	}
	/**
	 * @说明: 通过反射获取实例对象
	 * @param clz
	 * @param conn
	 * @return
	 */
	public static<T> T getInstance(Class<T> clz, Connection conn){
		
		T instance = null;
		try {
			Constructor<T> constructor = clz.getConstructor(Connection.class);
			instance = constructor.newInstance(conn);
		} catch (NoSuchMethodException e) {
			e.printStackTrace();
		} catch (SecurityException e) {
			e.printStackTrace();
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		}
		return instance;
	}
	
}
